package com.kehutong.charge.util;

import com.kehutong.charge.dto.MeterReadingImportDTO;
import org.coraframework.util.Objects;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * @program: kht
 * @description: ConvertUtil
 * @author: joneron
 * @create: 2021/6/30
 **/
public class ConvertUtil {

    public static List<Map<String, String>> concertEnumToListMap(Enum[] array) throws NoSuchFieldException, IllegalAccessException {
        List<Map<String, String>> list = new ArrayList<>();
        for (Enum obj : array) {
            Map<String, String> map = new LinkedHashMap<>();

            Field id = obj.getClass().getDeclaredField("id");
            id.setAccessible(true);
            Field desc = obj.getClass().getDeclaredField("desc");
            desc.setAccessible(true);

            map.put("id", id.get(obj).toString());
            map.put("desc", desc.get(obj).toString());
            list.add(map);
        }
        return list;
    }


    public static String jointAddress(String communityName,String buildName,String unitName,String house) {
        StringBuilder sb = new StringBuilder();
        if(!Objects.isEmpty(communityName)){
            sb.append(communityName.trim());
            sb.append("-");
        }
        sb.append(buildName.trim());
        if(!Objects.isBlank(unitName)){
            sb.append(unitName.trim());
        }
        sb.append("-");
        sb.append(house.trim());
        return sb.toString();
    }

}
